package com.zhengming.juc;

import java.util.Stack;

public class test {
    public static void main(String[] args) {
        String strA = "jiangzemin";
        Stack<Character> rs = new Stack<>();
        for (int i = 0; i < strA.length(); ++i) {
            rs.add(strA.charAt(i));
            Stack<Character> temp = new Stack<>();
            for (char c : rs) {
                temp.add(c);
                if (c <= strA.charAt(i)) {
                    temp.pop();
                    temp.add(strA.charAt(i));
                    rs = temp;
                    break;
                }
            }
        }
        System.out.println(rs);
    }
}
